<?php
/**
 * 春哥团队（www.cgtblog.com） - 春哥多端多商户万能DIY商城系统
 * Copyright © 2024 春哥技术团队 保留所有权利
 * =========================================================

 * ----------------------------------------------
 * 您只能在商业授权范围内使用，不可二次转售、分发、分享、传播
 * 任何企业和个人不得对代码以任何目的任何形式的再发布
 * =========================================================
 */

// +----------------------------------------------------------------------
// | 小程序设置
// +----------------------------------------------------------------------
namespace app\controller;
use think\facade\View;
use think\facade\Log;
use think\facade\Db;

class Wxset extends Common
{	
	//列表
    public function index(){
		$set = Db::name('admin_setapp_wx')->where('aid',aid)->find();
		if(!$set || $set['appid']==''){
			showmsg('请先创建或授权小程序');
		}
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$info = curl_get('https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo?access_token='.$access_token);
		$info = json_decode($info,true);
		//dump($info);
		if($info['errcode']){
			if($info['errcode']=='41033'){
				showmsg('非本平台创建的小程序无法设置，请前往微信公众平台进行设置(mp.weixin.qq.com)');
			}else{
				showmsg(\app\common\Wechat::geterror($info));
			}
		}else{
			//已设置的类目
			$category = curl_get('https://api.weixin.qq.com/cgi-bin/wxopen/getcategory?access_token='.$access_token);
			$category = json_decode($category,true);
			//dump($category);
			//是否可被搜索到
			$cansearch = curl_get('https://api.weixin.qq.com/wxa/getwxasearchstatus?access_token='.$access_token);
			$cansearch = json_decode($cansearch,true);
			//附近小程序地点列表
			$nearbypoidata = curl_get('https://api.weixin.qq.com/wxa/getnearbypoilist?page=1&page_rows=20&access_token='.$access_token);
			$nearbypoidata = json_decode($nearbypoidata,true);
			$poi_list = json_decode($nearbypoidata['data']['data'],true);

			//是否开通直播
			$url = 'https://api.weixin.qq.com/wxa/business/getliveinfo?access_token='.$access_token;
			$rs = request_post($url,jsonEncode(['start'=>0,'limit'=>1]));
			$rs = json_decode($rs,true);
			if(isset($rs['errcode']) && $rs['errcode']!=0 && $rs['errcode']!=1){//未开通
				$info['livestatus'] = 0;
			}else{
				$info['livestatus'] = 1;
			}


			$info['user_name'] = $set['nickname'];

			View::assign('info',$info);
			View::assign('category',$category);
			View::assign('cansearch',$cansearch);
			View::assign('nearbypoidata',$nearbypoidata);
			View::assign('poi_list',$poi_list);
			return View::fetch();
		}
    }
	//设置小程序名称
    public function setnickname(){
        $access_token = \app\common\Wechat::access_token(aid,'wx');
        $data = [];
        $data['nick_name'] = input('post.set_nickname_nickname');
        if(!$data['nick_name']){
            return json(['status'=>0,'msg'=>'请填写名称']);
        }
        if(input('post.set_nickname_id_card')){
            $data['id_card'] = \app\common\Wechat::pictomedia(aid,'wx',input('post.set_nickname_id_card'));
        }
        if(input('post.set_nickname_license')){
            $data['license'] = \app\common\Wechat::pictomedia(aid,'wx',input('post.set_nickname_license'));
        }
        if(input('post.naming_other_stuff_1')){
            $data['naming_other_stuff_1'] = \app\common\Wechat::pictomedia(aid,'wx',input('post.naming_other_stuff_1'));
        }
        $rs = curl_post('https://api.weixin.qq.com/wxa/setnickname?access_token='.$access_token,jsonEncode($data));
        $rs = json_decode($rs,true);
        if($rs['errcode']!=0){
            return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs).($rs['wording']?'-'.$rs['wording']:'')]);
        }else{
            Db::name('admin_setapp_wx')->where('aid',aid)->update(['nickname'=>$data['nick_name']]);
            if($rs['audit_id']){
                return json(['status'=>1,'msg'=>'名称已提交,请等待审核','url'=>(string)url('index')]);
            }else{
                return json(['status'=>1,'msg'=>'修改成功','url'=>(string)url('index')]);
            }
        }
    }
	//设置小程序头像
	public function setheadimg(){
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$headimg = input('post.set_headimg');
		if(!$headimg) return json(['status'=>0,'msg'=>'请上传头像']);
		$data = array();
		$data['head_img_media_id'] = \app\common\Wechat::pictomedia(aid,'wx',$headimg);
		$data['x1'] = 0;
		$data['y1'] = 0;
		$data['x2'] = 1;
		$data['y2'] = 1;
		$rs = curl_post('https://api.weixin.qq.com/cgi-bin/account/modifyheadimage?access_token='.$access_token,jsonEncode($data));
		$rs = json_decode($rs,true);
		//dump($data);
		if($rs['errcode']!=0){
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}else{
			$info = curl_get('https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo?access_token='.$access_token);
			$info = json_decode($info,true);
			$head_image_url = \app\common\Pic::uploadoss($info['head_image_info']['head_image_url']);
			Db::name('admin_setapp_wx')->where('aid',aid)->update(['headimg'=>$head_image_url]);
			return json(['status'=>1,'msg'=>'修改成功','url'=>(string)url('index')]);
		}
	}
	//设置小程序简介
	public function setsignature(){
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$signature = input('post.set_signature');
		$data = array('signature'=>$signature);
		$rs = curl_post('https://api.weixin.qq.com/cgi-bin/account/modifysignature?access_token='.$access_token,jsonEncode($data));
		$rs = json_decode($rs,true);
		//dump($data);
		if($rs['errcode']!=0){
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}else{
			Db::name('admin_setapp_wx')->where('aid',aid)->update(['signature'=>$signature]);
			return json(['status'=>1,'msg'=>'修改成功','url'=>(string)url('index')]);
		}
	}
	public function closesearch(){
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$data = array('status'=>1);
		$rs = curl_post('https://api.weixin.qq.com/wxa/changewxasearchstatus?access_token='.$access_token,jsonEncode($data));
		$rs = json_decode($rs,true);
		if($rs['errcode']!=0){
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}else{
			return json(['status'=>1,'msg'=>'修改成功','url'=>(string)url('index')]);
		}
	}
	public function opensearch(){
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$data = array('status'=>0);
		$rs = curl_post('https://api.weixin.qq.com/wxa/changewxasearchstatus?access_token='.$access_token,jsonEncode($data));
		$rs = json_decode($rs,true);
		if($rs['errcode']!=0){
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}else{
			return json(['status'=>1,'msg'=>'修改成功','url'=>(string)url('index')]);
		}
	}
	public function poiadd(){
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$related_proof_material = input('post.related_proof_material');
		$data = array();
		$data['related_name'] = $_POST['related_name'];
		$data['related_credential'] = $_POST['related_credential'];
		$data['related_address'] = $_POST['related_address'];
		if($related_proof_material){
			$data['related_proof_material'] = \app\common\Wechat::pictomedia(aid,'wx',$related_proof_material);
		}
		$rs = curl_post('https://api.weixin.qq.com/wxa/addnearbypoi?access_token='.$access_token,jsonEncode($data));
		$rs = json_decode($rs,true);
		if($rs['errcode']!=0){
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}else{
			return json(['status'=>1,'msg'=>'已提交,请等待审核','url'=>(string)url('index')]);
		}
	}
	public function setpoist(){
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$data = array();
		$data['poi_id'] = $_POST['poi_id'];
		$data['status'] = $_POST['st'];
		$rs = curl_post('https://api.weixin.qq.com/wxa/setnearbypoishowstatus?access_token='.$access_token,jsonEncode($data));
		$rs = json_decode($rs,true);
		if($rs['errcode']!=0){
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}else{
			return json(['status'=>1,'msg'=>'操作成功','url'=>(string)url('index')]);
		}
	}
	//申请开通小程序直播
	public function applylive(){
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$data = array();
		$data['action'] = 'apply';
		$rs = curl_post('https://api.weixin.qq.com/wxa/business/applyliveinfo?access_token='.$access_token,jsonEncode($data));
		$rs = json_decode($rs,true);
		if($rs['errcode']!=0){
			if($rs['errcode']==2){
				return json(['status'=>0,'msg'=>'小程序近90天没有存在支付行为，不能申请开通直播能力（数据生效时间为T+1，请耐心等待）']);
			}
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}else{
			return json(['status'=>1,'msg'=>'请小程序管理员在微信端点击消息通知卡片进入功能开通页面','url'=>(string)url('index')]);
		}
	}

	//设置用户隐私指引
	public function yinsi(){
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		if(request()->isPost()){
			$owner_setting = input('post.owner_setting/a');
			$setting_list = input('post.setting_list/a');
			
			$new_setting_list = [];
            foreach($setting_list as $k=>$v){
                if($v)
                    $new_setting_list[] = ['privacy_key'=>$k,'privacy_text'=>$v];
            }
			$postdata = [];
			$postdata['owner_setting'] = $owner_setting;
			$postdata['setting_list'] = $new_setting_list;
			$rs = curl_post('https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token='.$access_token,jsonEncode($postdata));
			$rs = json_decode($rs,true);
			if($rs['errcode']!=0){
				return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
			}else{
				return json(['status'=>1,'msg'=>'设置成功','url'=>true]);
			}
		}
		$rs = curl_post('https://api.weixin.qq.com/cgi-bin/component/getprivacysetting?access_token='.$access_token,'{}');
		$rs = json_decode($rs,true);
//        if(input('get.tt')){
//            dd($rs);
//        }
		if($rs['errcode']!=0){
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}

		$privacy_list = $rs['privacy_list'];
		$setting_list = $rs['setting_list'];
		$owner_setting = $rs['owner_setting'];
		$privacy_desc_list = $rs['privacy_desc']['privacy_desc_list'];

		$privacyArr = [];
		if($privacy_list){
			foreach($privacy_list as $k=>$v){
				$privacy_text = '';
				$privacy_desc = '';
				foreach($setting_list as $k2=>$v2){
					if($v2['privacy_key'] == $v){
						$privacy_text = $v2['privacy_text'];
					}
				}
				foreach($privacy_desc_list as $k3=>$v3){
					if($v3['privacy_key'] == $v){
						$privacy_desc = $v3['privacy_desc'];
					}
				}
				$privacyArr[$v] = ['desc'=>$privacy_desc,'text'=>$privacy_text];
			}
		}
        $newKey = 'privacy_key';
        $setting_listFormat = collect($setting_list)->dictionary(null, $newKey);
        $privacy_list_values = array_values($privacy_list);
        foreach($privacy_desc_list as $k3=>$v3){
            if(!in_array($v3['privacy_key'],$privacy_list_values)){
                $privacyArr[$v3['privacy_key']] = ['desc'=>$v3['privacy_desc'],'text'=>$setting_listFormat[$v3['privacy_key']]['privacy_text'] ?? ''];
            }
        }
//        if(input('get.pp')){
//            dd($privacyArr);
//        }
		View::assign('privacyArr',$privacyArr);
		View::assign('owner_setting',$owner_setting);
		return View::fetch();
	}

	//申请地理位置接口
	public function privacyInterfaceList(){
		
		if(request()->isAjax()){
			$access_token = \app\common\Wechat::access_token(aid,'wx');
			$rs = curl_get('https://api.weixin.qq.com/wxa/security/get_privacy_interface?access_token='.$access_token);
			$rs = json_decode($rs,true);
			if($rs['errcode']!=0){
				return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
			}
			$interface_list = $rs['interface_list'];
			$chooseLocation = [];
			$chooseAddress = [];
			$getLocation = [];
			$new_interface_list = [];
			foreach($interface_list as $k=>$v){
				if($v['api_name'] == 'wx.chooseLocation'){
					$chooseLocation = $v;
				}elseif($v['api_name'] == 'wx.chooseAddress'){
					$chooseAddress = $v;
				}elseif($v['api_name'] == 'wx.getLocation'){
					$getLocation = $v;
				}else{
					$new_interface_list[] = $v;
				}
			}
			if($getLocation){
				$new_interface_list = array_merge([$getLocation],$new_interface_list);
			}
			if($chooseAddress){
				$new_interface_list = array_merge([$chooseAddress],$new_interface_list);
			}
			if($chooseLocation){
				$new_interface_list = array_merge([$chooseLocation],$new_interface_list);
			}
			return json(['code'=>0,'msg'=>'查询成功','count'=>count($new_interface_list),'data'=>$new_interface_list]);
		}
		return View::fetch();
	}
	public function applyPrivacyInterface(){
		$info = input('post.info/a');
		$postdata = [];
		$postdata['api_name'] = $info['api_name'];
		$postdata['content'] = $info['content'];
		$postdata['pic_list'] = $info['pic_list'] ? explode(',',$info['pic_list']) : [];
		$postdata['video_list'] = $info['video'] ? [$info['video']] : [];
		$postdata['url_list'] = $info['url'] ? [$info['url']] : [];
		//var_dump($postdata);
		if(!$postdata['content']) return json(['status'=>0,'msg'=>'请填写申请原因']);
		$access_token = \app\common\Wechat::access_token(aid,'wx');
		$rs = curl_post('https://api.weixin.qq.com/wxa/security/apply_privacy_interface?access_token='.$access_token,jsonEncode($postdata));
		$rs = json_decode($rs,true);
		if($rs['errcode']!=0){
			return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
		}
		return json(['status'=>1,'msg'=>'提交成功']);
	}


    //备案 https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/record/queryIcpVerifyTask.html
    public function icp(){
        /**
         * 流程：是否人脸核身，否-》发起人脸核身
         * 是
         */
        $info = input('post.info/a');
//        $access_token = \app\common\Wechat::access_token(aid,'wx');
        if(request()->isPost()){
//            $owner_setting = input('post.owner_setting/a');
//            $setting_list = input('post.setting_list/a');
//
//            $new_setting_list = [];
//            foreach($setting_list as $k=>$v){
//                $new_setting_list[] = ['privacy_key'=>$k,'privacy_text'=>$v];
//            }
//            $postdata = [];
//            $postdata['owner_setting'] = $owner_setting;
//            $postdata['setting_list'] = $new_setting_list;
//            $rs = curl_post('https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token='.$access_token,jsonEncode($postdata));
//            $rs = json_decode($rs,true);
//            if($rs['errcode']!=0){
//                return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
//            }else{
//                return json(['status'=>1,'msg'=>'设置成功','url'=>true]);
//            }
//        }
//        $rs = curl_post('https://api.weixin.qq.com/cgi-bin/component/getprivacysetting?access_token='.$access_token,'{}');
//        $rs = json_decode($rs,true);
//        if($rs['errcode']!=0){
//            return json(['status'=>0,'msg'=>\app\common\Wechat::geterror($rs)]);
//        }
//
//        $privacy_list = $rs['privacy_list'];
//        $setting_list = $rs['setting_list'];
//        $owner_setting = $rs['owner_setting'];
//        $privacy_desc_list = $rs['privacy_desc']['privacy_desc_list'];
//
//        $privacyArr = [];
//        if($privacy_list){
//            foreach($privacy_list as $k=>$v){
//                $privacy_text = '';
//                $privacy_desc = '';
//                foreach($setting_list as $k2=>$v2){
//                    if($v2['privacy_key'] == $v){
//                        $privacy_text = $v2['privacy_text'];
//                    }
//                }
//                foreach($privacy_desc_list as $k3=>$v3){
//                    if($v3['privacy_key'] == $v){
//                        $privacy_desc = $v3['privacy_desc'];
//                    }
//                }
//                $privacyArr[$v] = ['desc'=>$privacy_desc,'text'=>$privacy_text];
//            }
        }
//        $ContentTypes = \app\common\Wechat::queryIcpServiceContentTypes(aid);
        $ContentTypes = json_decode('[{"type":1,"parent_type":500,"name":"生活缴费","remark":"水电煤气话费等"},{"type":2,"parent_type":500,"name":"招聘"},{"type":3,"parent_type":500,"name":"工具","remark":"笔记、日历、记账、投票、天气、备忘录、办公、图片处理、计算器、报价\\/比价、信息查询、发票查询、预约\\/报名、字典、邮箱、输入法、投票、菜谱、ar识别、广告图文、回收租赁、寄存等"},{"type":4,"parent_type":500,"name":"家政","remark":"清洁、维修、开锁等"},{"type":5,"parent_type":500,"name":"婚庆"},{"type":6,"parent_type":500,"name":"房地产","remark":"租房、销售、中介、物业、装修等"},{"type":7,"parent_type":500,"name":"母婴"},{"type":8,"parent_type":500,"name":"共享服务","remark":"单车、充电宝等"},{"type":9,"parent_type":500,"name":"丽人","remark":"美甲、美容、美发、纹身等"},{"type":10,"parent_type":500,"name":"洗浴保健"},{"type":11,"parent_type":500,"name":"宠物"},{"type":12,"parent_type":500,"name":"法律咨询"},{"type":13,"parent_type":500,"name":"公证"},{"type":14,"parent_type":500,"name":"电子认证"},{"type":15,"parent_type":500,"name":"拍卖","remark":"文物、非文物、司法拍卖等"},{"type":16,"parent_type":500,"name":"专利\\/商标代理"},{"type":17,"parent_type":500,"name":"亲子\\/司法鉴定"},{"type":18,"parent_type":500,"name":"会计师事务所"},{"type":19,"parent_type":500,"name":"税务师事务所"},{"type":20,"parent_type":500,"name":"公共印章刻制"},{"type":21,"parent_type":500,"name":"公司转让信息服务"},{"type":22,"parent_type":500,"name":"一般财务服务"},{"type":23,"parent_type":500,"name":"公关\\/推广\\/市场调查"},{"type":24,"parent_type":500,"name":"网络代理"},{"type":25,"parent_type":500,"name":"企业管理"},{"type":26,"parent_type":500,"name":"会展服务"},{"type":27,"parent_type":500,"name":"出国移民"},{"type":28,"parent_type":500,"name":"摄影\\/扩印"},{"type":29,"parent_type":500,"name":"质量检测"},{"type":30,"parent_type":500,"name":"机械维修"},{"type":31,"parent_type":500,"name":"工商代理注册"},{"type":32,"parent_type":500,"name":"其他"},{"type":33,"parent_type":501,"name":"点餐"},{"type":34,"parent_type":501,"name":"外卖"},{"type":35,"parent_type":501,"name":"其他"},{"type":36,"parent_type":502,"name":"福利彩票"},{"type":37,"parent_type":502,"name":"游戏"},{"type":38,"parent_type":502,"name":"歌舞厅、KTV等娱乐、休闲娱乐类服务"},{"type":39,"parent_type":502,"name":"健身房\\/瑜伽\\/舞蹈\\/美体机构"},{"type":40,"parent_type":502,"name":"棋牌桌游\\/电玩网吧"},{"type":41,"parent_type":502,"name":"网络社交","remark":"熟人社交、陌生人社交、婚恋、社区\\/论坛、直播、会议、问答、直播答题等"},{"type":42,"parent_type":502,"name":"网络图书","remark":"电子书、网络小说、学术期刊等"},{"type":43,"parent_type":502,"name":"视频","remark":"在线观看、视频广场、短视频等"},{"type":44,"parent_type":502,"name":"音乐、电台、有声读物"},{"type":45,"parent_type":502,"name":"文化场馆"},{"type":46,"parent_type":502,"name":"体育","remark":"场馆、赛事、培训等"},{"type":47,"parent_type":502,"name":"游乐园、嘉年华"},{"type":48,"parent_type":502,"name":"院线影城、演出"},{"type":49,"parent_type":503,"name":"景区服务"},{"type":50,"parent_type":503,"name":"旅行社"},{"type":51,"parent_type":503,"name":"旅游管理单位"},{"type":52,"parent_type":503,"name":"旅游退税"},{"type":53,"parent_type":503,"name":"OTA（在线旅行社）","remark":"在线旅行社，例如飞猪，携程等"},{"type":54,"parent_type":503,"name":"住宿服务"},{"type":55,"parent_type":503,"name":"出境","remark":"签证、wifi、国际驾照等"},{"type":56,"parent_type":503,"name":"其他"},{"type":57,"parent_type":504,"name":"火车\\/高铁\\/动车"},{"type":58,"parent_type":504,"name":"航空"},{"type":59,"parent_type":504,"name":"公交\\/地铁"},{"type":60,"parent_type":504,"name":"打车\\/出租车"},{"type":61,"parent_type":504,"name":"自行车"},{"type":62,"parent_type":504,"name":"长途汽车"},{"type":63,"parent_type":504,"name":"船舶","remark":"港口等"},{"type":64,"parent_type":504,"name":"导航"},{"type":65,"parent_type":504,"name":"加油"},{"type":66,"parent_type":504,"name":"高速"},{"type":67,"parent_type":504,"name":"其他"},{"type":68,"parent_type":505,"name":"维修保养","remark":"维修\\/美容\\/养护\\/洗车等"},{"type":69,"parent_type":505,"name":"汽车用品","remark":"各种交通工具零部件、内饰\\/外饰等"},{"type":70,"parent_type":505,"name":"车辆销售\\/二手车销售","remark":"销售、估值、报价、查询（车、车企、经销商、4s店）、车展等"},{"type":71,"parent_type":505,"name":"代驾"},{"type":72,"parent_type":505,"name":"租车"},{"type":73,"parent_type":505,"name":"停车"},{"type":74,"parent_type":505,"name":"充电"},{"type":75,"parent_type":505,"name":"Etc"},{"type":76,"parent_type":505,"name":"道路救援"},{"type":77,"parent_type":505,"name":"车联网"},{"type":78,"parent_type":506,"name":"儿童教育"},{"type":79,"parent_type":506,"name":"培训机构","remark":"驾校、国内、国外、艺术类、线上线下、特殊教育等"},{"type":80,"parent_type":506,"name":"学校","remark":"校园服务等"},{"type":81,"parent_type":506,"name":"其他"},{"type":82,"parent_type":507,"name":"快递"},{"type":83,"parent_type":507,"name":"物流"},{"type":84,"parent_type":507,"name":"仓储"},{"type":85,"parent_type":507,"name":"快递柜"},{"type":86,"parent_type":507,"name":"其他"},{"type":87,"parent_type":508,"name":"医院","remark":"私立、公立、社区卫生站、就医服务等"},{"type":88,"parent_type":508,"name":"医疗器械"},{"type":89,"parent_type":508,"name":"医药"},{"type":90,"parent_type":508,"name":"健康护理"},{"type":91,"parent_type":508,"name":"血液、干细胞服务","remark":"献血"},{"type":92,"parent_type":508,"name":"临床试验"},{"type":93,"parent_type":509,"name":"时政信息"},{"type":94,"parent_type":509,"name":"政务服务大厅"},{"type":95,"parent_type":509,"name":"交通出行及运输","remark":"出行、运输、交管、航空"},{"type":96,"parent_type":509,"name":"户政"},{"type":97,"parent_type":509,"name":"公安（含国安）及消防"},{"type":98,"parent_type":509,"name":"出境入境及边防"},{"type":99,"parent_type":509,"name":"司法公证","remark":"司法 检查 法院"},{"type":100,"parent_type":509,"name":"纪检审计"},{"type":101,"parent_type":509,"name":"财政"},{"type":102,"parent_type":509,"name":"民政"},{"type":103,"parent_type":509,"name":"住房保障","remark":"住建 公积金"},{"type":104,"parent_type":509,"name":"党\\/团\\/组织"},{"type":105,"parent_type":509,"name":"文体及教育科研"},{"type":106,"parent_type":509,"name":"人力资源及社会保障","remark":"人力资源中积分政策合并入户籍办理"},{"type":107,"parent_type":509,"name":"环保绿化"},{"type":108,"parent_type":509,"name":"水利水务"},{"type":109,"parent_type":509,"name":"气象地质"},{"type":110,"parent_type":509,"name":"市场监督管理"},{"type":111,"parent_type":509,"name":"医疗卫生"},{"type":112,"parent_type":509,"name":"国土规划建设"},{"type":113,"parent_type":509,"name":"质量技术"},{"type":114,"parent_type":509,"name":"食品监督管理","remark":"食品监督管理部门比较多，涉及卫生部、农业部、市监局、药监局、工信部等"},{"type":115,"parent_type":509,"name":"新闻出版及广电"},{"type":116,"parent_type":509,"name":"税收财务"},{"type":117,"parent_type":509,"name":"金融"},{"type":118,"parent_type":509,"name":"知识产权"},{"type":119,"parent_type":509,"name":"信访"},{"type":120,"parent_type":509,"name":"公用事业","remark":"城管、街道居委、城市道路"},{"type":121,"parent_type":509,"name":"海关口岸","remark":"海关改为海关口岸"},{"type":122,"parent_type":509,"name":"邮政"},{"type":123,"parent_type":509,"name":"检验检疫"},{"type":124,"parent_type":509,"name":"商务贸易","remark":"商务改为商务贸易"},{"type":125,"parent_type":509,"name":"农林畜牧海洋"},{"type":126,"parent_type":509,"name":"社科档案及文物"},{"type":127,"parent_type":509,"name":"安全生产及应急"},{"type":128,"parent_type":509,"name":"科技创新"},{"type":129,"parent_type":509,"name":"统计"},{"type":130,"parent_type":509,"name":"经济发展与改革"},{"type":131,"parent_type":509,"name":"烟草"},{"type":132,"parent_type":509,"name":"网信"},{"type":133,"parent_type":509,"name":"工信"},{"type":134,"parent_type":509,"name":"能源","remark":"新增能源，包括电力、燃气等资源管理"},{"type":135,"parent_type":509,"name":"乡村振兴"},{"type":136,"parent_type":509,"name":"民族宗教"},{"type":137,"parent_type":509,"name":"信用"},{"type":138,"parent_type":509,"name":"公益"},{"type":139,"parent_type":510,"name":"保险","remark":"第三方互联网保险等"},{"type":140,"parent_type":510,"name":"银行","remark":"信用卡、电子汇票等"},{"type":141,"parent_type":510,"name":"信托"},{"type":142,"parent_type":510,"name":"公募基金"},{"type":143,"parent_type":510,"name":"私募基金"},{"type":144,"parent_type":510,"name":"证券\\/期货","remark":"投资咨询等"},{"type":145,"parent_type":510,"name":"非金融机构自营小额贷款"},{"type":146,"parent_type":510,"name":"融资担保"},{"type":147,"parent_type":510,"name":"商业保理"},{"type":148,"parent_type":510,"name":"汽车金融\\/融资租赁"},{"type":149,"parent_type":510,"name":"征信业务"},{"type":150,"parent_type":510,"name":"新三板信息服务平台"},{"type":151,"parent_type":510,"name":"股票信息服务平台（港股\\/美股）"},{"type":152,"parent_type":510,"name":"股票信息服务平台"},{"type":153,"parent_type":510,"name":"外币兑换"},{"type":154,"parent_type":510,"name":"实物黄金买卖"},{"type":155,"parent_type":510,"name":"消费金融"},{"type":156,"parent_type":510,"name":"收单商户服务"},{"type":157,"parent_type":510,"name":"区域性股权交易市场"},{"type":158,"parent_type":511,"name":"音视频设备","remark":"设备购买服务，视频线、摄像头等"},{"type":159,"parent_type":511,"name":"电信业务","remark":"运营商、业务代理、转售等"},{"type":160,"parent_type":511,"name":"多方通信"},{"type":161,"parent_type":511,"name":"软件开发"},{"type":162,"parent_type":511,"name":"网络推广"},{"type":163,"parent_type":512,"name":"零售批发","remark":"电商、超市便利店等"},{"type":164,"parent_type":512,"name":"自主售卖"},{"type":165,"parent_type":512,"name":"百货商场\\/购物中心"},{"type":166,"parent_type":513,"name":"安全生产"},{"type":167,"parent_type":513,"name":"杀毒软件","remark":"又叫反病毒软件.如，G+Data（德国）、360杀毒、卡巴斯基安全部队、小红伞、瑞星杀毒软件、金山毒霸等"},{"type":168,"parent_type":513,"name":"辅助性安全软件","remark":"主要是清理垃圾、修复漏洞、防木马的软件，比如360安全卫士、金山卫士、瑞星安全助手等等"},{"type":169,"parent_type":513,"name":"反流氓软件","remark":"主要是清理流氓软件，保护系统安全的功能.如360安全卫士、恶意软件清理助手、超级兔子、Windows清理助手等等"},{"type":170,"parent_type":513,"name":"加密软件","remark":"主要是通过对数据文件进行加密，防止外泄，从而确保信息资产的安全！加密软件按照实现的方法可划分为被动加密和主动加密。目前市面上的驱动层透明加密技术成为了最可靠、最安全的加密技术，代表厂商有广东南方信息安全产业基地"},{"type":171,"parent_type":513,"name":"其他"},{"type":172,"parent_type":514,"name":"工业研发设计"},{"type":173,"parent_type":514,"name":"生产管理"},{"type":174,"parent_type":514,"name":"其他"},{"type":175,"parent_type":515,"name":"宗教信息"},{"type":176,"parent_type":515,"name":"咨询广场"},{"type":500,"parent_type":0,"name":"生活服务"},{"type":501,"parent_type":0,"name":"餐饮"},{"type":502,"parent_type":0,"name":"休闲娱乐"},{"type":503,"parent_type":0,"name":"旅游服务"},{"type":504,"parent_type":0,"name":"交通运输"},{"type":505,"parent_type":0,"name":"汽车服务"},{"type":506,"parent_type":0,"name":"教育"},{"type":507,"parent_type":0,"name":"仓储和邮政业"},{"type":508,"parent_type":0,"name":"医疗服务"},{"type":509,"parent_type":0,"name":"政务服务"},{"type":510,"parent_type":0,"name":"金融业"},{"type":511,"parent_type":0,"name":"信息传输、软件和信息技术服务业"},{"type":512,"parent_type":0,"name":"批发和零售业"},{"type":513,"parent_type":0,"name":"安全"},{"type":514,"parent_type":0,"name":"工业互联网软件"},{"type":515,"parent_type":0,"name":"其他"}]',true);
        View::assign('ContentTypes',$this->formatContentTypes($ContentTypes));
//        $CertificateTypes = \app\common\Wechat::queryIcpCertificateTypes(aid);
        $CertificateTypes = json_decode('[{"type":1,"subject_type":4,"name":"营业执照（个人或企业）"},{"type":2,"subject_type":5,"name":"居民身份证"},{"type":3,"subject_type":3,"name":"组织机构代码证"},{"type":4,"subject_type":3,"name":"事业单位法人证书"},{"type":5,"subject_type":1,"name":"部队代号"},{"type":6,"subject_type":6,"name":"社会团体法人登记证书"},{"type":7,"subject_type":5,"name":"护照"},{"type":9,"subject_type":2,"name":"组织机构代码证"},{"type":10,"subject_type":6,"name":"组织机构代码证"},{"type":11,"subject_type":5,"name":"台湾居民来往大陆通行证"},{"type":12,"subject_type":4,"name":"组织机构代码证"},{"type":13,"subject_type":2,"name":"统一社会信用代码证书"},{"type":14,"subject_type":5,"name":"港澳居民来往内地通行证"},{"type":15,"subject_type":3,"name":"统一社会信用代码证书"},{"type":16,"subject_type":9,"name":"组织机构代码证"},{"type":17,"subject_type":9,"name":"民办非企业单位登记证书"},{"type":18,"subject_type":10,"name":"组织机构代码证"},{"type":19,"subject_type":10,"name":"基金会法人登记证书"},{"type":20,"subject_type":11,"name":"组织机构代码证"},{"type":21,"subject_type":11,"name":"律师事务所执业许可证"},{"type":22,"subject_type":12,"name":"外国在华文化中心登记证","remark":"关于外国政府在中国设立的文化中心办理全国组织机构代码证有关事项的通知（文外函[2009]199号）"},{"type":23,"subject_type":1,"name":"军队单位对外有偿服务许可证"},{"type":24,"subject_type":13,"name":"统一社会信用代码证书"},{"type":25,"subject_type":15,"name":"宗教活动场所登记证"},{"type":27,"subject_type":4,"name":"外国企业常驻代表机构登记证","remark":"中华人民共和国国务院令第584号《外国企业常驻代表机构登记管理条例》"},{"type":28,"subject_type":14,"name":"司法鉴定许可证","remark":"司法鉴定许可证登记统一社会信用代码号"},{"type":30,"subject_type":5,"name":"外国人永久居留身份证","remark":"工信管函(2O17)1488号"},{"type":34,"subject_type":12,"name":"外国政府旅游部门常驻代表机构批准登记证"},{"type":35,"subject_type":16,"name":"境外机构证件","remark":"国外结构所持有的证件号码"},{"type":36,"subject_type":9,"name":"社会服务机构登记证书"},{"type":37,"subject_type":9,"name":"民办学校办学许可证"},{"type":38,"subject_type":17,"name":"医疗机构执业许可证"},{"type":39,"subject_type":18,"name":"公证机构执业证"},{"type":40,"subject_type":12,"name":"北京市外国驻华使馆人员子女学校办学许可证"},{"type":41,"subject_type":5,"name":"港澳居民居住证"},{"type":42,"subject_type":5,"name":"台湾居民居住证"},{"type":43,"subject_type":19,"name":"农村集体经济组织登记证"},{"type":44,"subject_type":20,"name":"仲裁委员会登记证"}]',true);
        View::assign('CertificateTypes',$CertificateTypes);
//        $DistrictCode = \app\common\Wechat::queryIcpDistrictCode(aid);
//        View::assign('DistrictCode',$DistrictCode);
//        $NrlxTypes = \app\common\Wechat::queryIcpNrlxTypes(aid);//前置审批项
        $NrlxTypes = json_decode('[{"type":1,"name":"新闻"},{"type":2,"name":"出版"},{"type":3,"name":"教育"},{"type":4,"name":"医疗保健"},{"type":5,"name":"药品和医疗器械"},{"type":6,"name":"电子公告服务"},{"type":9,"name":"文化"},{"type":10,"name":"广播电影电视节目"},{"type":12,"name":"网络预约车"},{"type":13,"name":"互联网金融"},{"type":14,"name":"校外培训"},{"type":15,"name":"宗教"},{"type":24,"name":"以上都不涉及"}]',true);
        View::assign('NrlxTypes',$NrlxTypes);
//        $SubjectTypes = \app\common\Wechat::queryIcpSubjectTypes(aid);
        $SubjectTypes = json_decode('[{"type":1,"name":"国防机构"},{"type":2,"name":"政府机关"},{"type":3,"name":"事业单位"},{"type":4,"name":"企业"},{"type":5,"name":"个人"},{"type":6,"name":"社会团体"},{"type":9,"name":"民办非企业单位"},{"type":10,"name":"基金会"},{"type":11,"name":"律师执业机构"},{"type":12,"name":"外国在华文化中心","remark":"关于外国政府在中国设立的文化中心办理全国组织机构代码证有关事项的通知（文外函[2009]199号）"},{"type":13,"name":"群众性团体组织"},{"type":14,"name":"司法鉴定机构"},{"type":15,"name":"宗教团体"},{"type":16,"name":"境外机构"},{"type":17,"name":"医疗机构"},{"type":18,"name":"公证机构"},{"type":19,"name":"集体经济"},{"type":20,"name":"仲裁机构"}]',true);
        View::assign('SubjectTypes',$SubjectTypes);
        return View::fetch();
    }

    private function formatContentTypes($ContentTypes)
    {
        $newArr = [];
        foreach ($ContentTypes as $item){
            if($item['parent_type'] == 0)
                $newArr[$item['type']] = $item;
        }
        foreach ($ContentTypes as $item){
            if($item['parent_type'] > 0)
                $newArr[$item['parent_type']]['child'][] = $item;
        }
        return $newArr;
    }
}